package com.system.presideover.utils;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;


@Configuration
public class WebConfig implements WebMvcConfigurer {



    @Resource
    private GetTokenInterceptor getTokenInterceptor;

    @Resource
    private LoginCheckInterceptor loginCheckInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginCheckInterceptor)
                .excludePathPatterns("/presideover/applet-user/getHeadAndName/**")
                .excludePathPatterns("/presideover/emcee/listEmcee")
                .excludePathPatterns("/presideover/slideshow/listSlideshow")
                .excludePathPatterns("/presideover/account-number/login")
                .excludePathPatterns("/presideover/file/upload/download/**")
                .excludePathPatterns("/presideover/common/download/**")
                .excludePathPatterns("/presideover/emcee/emceelsl/**")
                .excludePathPatterns("/presideover/auction-calendar/listAuctionCalendar")
                .excludePathPatterns("/files/**")
                .excludePathPatterns("/presideover/account-number/logout")
                .excludePathPatterns("/presideover/schedule/filterSchedule")
                .excludePathPatterns("/presideover/common/delectPrcture")
                .excludePathPatterns("/presideover/file/upload/delectVideo")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**","/doc.html/**", "/swagger-ui.html/**")
                .addPathPatterns("/**");

        registry.addInterceptor(getTokenInterceptor)
                .excludePathPatterns("/presideover/applet-user/getHeadAndName/**")
                .excludePathPatterns("/presideover/emcee/listEmcee")
                .excludePathPatterns("/presideover/slideshow/listSlideshow")
                .excludePathPatterns("/presideover/account-number/login")
                .excludePathPatterns("/presideover/file/upload/download/**")
                .excludePathPatterns("/presideover/common/download/**")
                .excludePathPatterns("/presideover/emcee/emceelsl/**")
                .excludePathPatterns("/presideover/auction-calendar/listAuctionCalendar")
                .excludePathPatterns("/files/**")
                .excludePathPatterns("/presideover/account-number/logout")
                .excludePathPatterns("/presideover/schedule/filterSchedule")
                .excludePathPatterns("/presideover/common/delectPrcture")
                .excludePathPatterns("/presideover/file/upload/delectVideo")
//                .excludePathPatterns("/presideover/file/upload/**")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**","/doc.html/**", "/swagger-ui.html/**")
                .addPathPatterns("/**");
    }



    /**
     * 配置静态资源映射
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /*
        http://localhost:8080/play/1.mp4
        下面配置的大概意思就是，只有在url中是以play开头（如：http://localhost:8080/play）+ 文件名
        就到文件夹中如（D:\private\javastudaykeshanchu\video\）找到对应的图片或视频，就可以在浏览器地址栏中显示了
         */
        registry.addResourceHandler("/files/**").addResourceLocations("file:/home/wwwroot/presideover/file/image/")
                                                                .addResourceLocations("file:/home/wwwroot/presideover/file/video/");
    }



}
